package com.leo.ssh2.framework.action;


import com.leo.ssh2.framework.dto.User;
import com.leo.ssh2.framework.service.IUserDAO;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
	
	private User user;

	private IUserDAO userDAO;
	
    @Override
    public String execute() throws Exception {

    	//we will do login logic here
    	User result = userDAO.query(user);
    	
    	if (result == null) {
    		
    		user.setName("you can't logon this system");
    		return ERROR;
    	}
    	
    	if (result.getId().equals(user.getId())
    			&& result.getPassword().equals(user.getPassword())) {
            return SUCCESS;
    	} else {
    		
    		user.setName("you can't logon this system");
    		return ERROR;
    	}
    }

    @Override
    public void validate() {

    	if (null == user.getId() || "".equals(user.getId())) {
    		addFieldError("user.id", "you must input id");
    	}
    }

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public IUserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(IUserDAO userDAO) {
		this.userDAO = userDAO;
	}
    
    
}
